<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var str = [1,8,6,2,5,4,8,3,7]
    var maxArea = function(height) {
        var first = 0
        var last=height.length-1
        v = []
        while(first!=last){
            l=Math.abs(last-first)
            h = height[first]>height[last] ? height[last]:height[first]
            height[first]>height[last] ? last--:first++
            v.push(l*h)
        }
        v.sort(function(a,b){return b-a})
        console.log(v)
    }
    maxArea(str)
    </script>
</body>
</html>